package com.ssy.lingxi.marketing.controller.coupon;

import com.ssy.lingxi.common.constant.marketing.PlatformCouponTypeEnum;
import com.ssy.lingxi.common.constant.member.MemberTypeEnum;
import com.ssy.lingxi.common.constant.member.PlatformSuitableMemberEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.SelectItemVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.model.constant.PlatformCouponGetWayEnum;
import com.ssy.lingxi.marketing.model.constant.PlatformCouponStatusEnum;
import com.ssy.lingxi.marketing.model.vo.common.request.CommonAgreeRequest;
import com.ssy.lingxi.marketing.model.vo.common.request.CommonIdReq;
import com.ssy.lingxi.marketing.model.vo.common.request.CommonIdsRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.*;
import com.ssy.lingxi.marketing.model.vo.coupon.response.*;
import com.ssy.lingxi.marketing.service.IPlatformCouponService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *
 * @menu 平台优惠劵管理
 * @author yzc
 * @version 2.0.0
 * @date 2021/6/28
 */
@RestController
@RequestMapping("/marketing/coupon/platform")
public class PlatformCouponController extends BaseController {

    @Resource
    private IPlatformCouponService platformCouponService;

    // =============================状态列表=============================

    /**
     * 1-0元购买抵扣券 2-平台通用优惠券
     * @description 优惠券类型列表
     * @return 查询结果
     */
    @RequestMapping(value = "/typeList", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listPlatformCouponType() {
        List<SelectItemVO> statusVOList = Stream.of(PlatformCouponTypeEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        return Wrapper.success(statusVOList);
    }

    /**
     * 1-前台用户领券 2-指定会员发券 3-营销活动用券 4-会员运营用券
     * @description 优惠券领取方式列表
     * @return 查询结果
     */
    @RequestMapping(value = "/getWayList", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listPlatformCouponGetWay() {
        List<SelectItemVO> statusVOList = Stream.of(PlatformCouponGetWayEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        return Wrapper.success(statusVOList);
    }

    /**
     * 1-待提交审核 2-待审核(一级) 3-待审核不通过(一级) 4-待审核(二级) 5-待审核不通过(二级) 6-待提交 7-待执行 8-进行中 9-已终止 10-已取消 11-已结束
     * @description 优惠券状态列表
     * @return 查询结果
     */
    @RequestMapping(value = "statusList", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listPlatformCouponStatus() {
        List<SelectItemVO> statusVOList = Stream.of(PlatformCouponStatusEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        return Wrapper.success(statusVOList);
    }


    /**
     * 1-企业会员 2-个人会员
     * @description 优惠券适用会员类型列表
     * @return 查询结果
     */
    @RequestMapping(value = "/memberTypeList", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listMemberType() {
        List<SelectItemVO> statusVOList = Stream.of(MemberTypeEnum.MERCHANT, MemberTypeEnum.MERCHANT_PERSONAL).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        return Wrapper.success(statusVOList);
    }

    /**
     * 1-新用户 2-老用户
     * @description 优惠券适用会员列表
     * @return 查询结果
     */
    @RequestMapping(value = "suitableMemberTypeList", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> listSuitableMemberTypeList() {
        List<SelectItemVO> statusVOList = Stream.of(PlatformSuitableMemberEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        return Wrapper.success(statusVOList);
    }

    /**
     * 平台优惠券分页列表查询条件
     * @return 返回结果
     */
    @RequestMapping(value = "/page/condition", method = RequestMethod.GET)
    public Wrapper<PlatformCouponConditionResponse> listPlatformCouponCondition() {
        PlatformCouponConditionResponse conditionResponse = new PlatformCouponConditionResponse();
        List<SelectItemVO> typeList = Stream.of(PlatformCouponTypeEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        conditionResponse.setTypeList(typeList);

        List<SelectItemVO> getWayList = Stream.of(PlatformCouponGetWayEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        conditionResponse.setGetWayList(getWayList);

        List<SelectItemVO> statusList = Stream.of(PlatformCouponStatusEnum.values()).map(e -> {
            SelectItemVO response = new SelectItemVO();
            response.setValue(e.getCode());
            response.setName(e.getMessage());
            return response;
        }).collect(Collectors.toList());
        conditionResponse.setStatusList(statusList);

        return Wrapper.success(conditionResponse);
    }

    // =============================平台优惠劵查询=============================

    /**
     * 平台优惠劵查询 - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/summary/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSummaryPageResponse>> pageSummaryPlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageSummaryPlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵查询 - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/summary/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getSummaryPlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵查询 - 修改
     * @param request 接口参数
     */

    @RequestMapping(value = "/waitAudit/modification", method = RequestMethod.POST)
    public Wrapper<Void> modificationPlatformCoupon(@RequestBody @Valid PlatformCouponModificationRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.modificationPlatformCoupon(request, loginUser);
    }


    /**
     * 平台优惠劵查询 - 终止
     * @param request 接口参数
     */
    @RequestMapping(value = "/summary/stop", method = RequestMethod.POST)
    public Wrapper<Void> stopPlatformCoupon(@RequestBody @Valid PlatformCouponOperationRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.stopPlatformCoupon(request, loginUser);
    }


    /**
     * 平台优惠劵查询 - 重启
     * @param request 接口参数
     */
    @RequestMapping(value = "/summary/restart", method = RequestMethod.POST)
    public Wrapper<Void> restartPlatformCoupon(@RequestBody @Valid PlatformCouponOperationRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.restartPlatformCoupon(request, loginUser);
    }


    /**
     * 平台优惠劵查询 - 取消
     * @param request 接口参数
     */
    @RequestMapping(value = "/summary/cancel", method = RequestMethod.POST)
    public Wrapper<Void> cancelPlatformCoupon(@RequestBody @Valid PlatformCouponOperationRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.cancelPlatformCoupon(request, loginUser);
    }


    // =============================待提交审核平台优惠劵=============================

    /**
     * 待提交审核平台优惠劵 - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAudit/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSubmitAuditPageResponse>> pageWaitAuditPlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageSubmitAuditPlatformCoupon(request, loginUser);
    }

    /**
     * 待提交审核平台优惠劵 - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAudit/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getWaitAuditPlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }

    /**
     * 待提交审核平台优惠劵 - 新增
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAudit/add", method = RequestMethod.POST)
    public Wrapper<Void> addPlatformCoupon(@RequestBody @Valid PlatformCouponAddRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.addPlatformCoupon(request, loginUser);
    }

    /**
     * 待提交审核平台优惠劵 - 修改
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAudit/update", method = RequestMethod.POST)
    public Wrapper<Void> updatePlatformCoupon(@RequestBody @Valid PlatformCouponUpdateRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.updatePlatformCoupon(request, loginUser);
    }

    /**
     * 待提交审核平台优惠劵 - 删除
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAudit/delete", method = RequestMethod.POST)
    public Wrapper<Void> deletePlatformCoupon(@RequestBody @Valid CommonIdsRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.deletePlatformCoupon(request, loginUser);
    }

    /**
     * 待提交审核平台优惠劵 - 提交审核
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAudit/submitBatch", method = RequestMethod.POST)
    public Wrapper<Void> submitBatchAuditPlatformCoupon(@RequestBody @Valid CommonIdsRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.submitAuditPlatformCoupon(request, loginUser);
    }

    // =============================待审核平台优惠劵(一级)=============================

    /**
     * 待审核平台优惠劵(一级) - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAuditOne/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponAuditPageResponse>> pageAuditOnePlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageAuditOnePlatformCoupon(request, loginUser);
    }

    /**
     * 待审核平台优惠劵(一级) - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAuditOne/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getAuditOnePlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }


    /**
     * 待审核平台优惠劵(一级) - 提交审核
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAuditOne/audit", method = RequestMethod.POST)
    public Wrapper<Void> auditOnePlatformCoupon(@RequestBody @Valid CommonAgreeRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.auditOnePlatformCoupon(request, loginUser);
    }

    /**
     * 待审核平台优惠劵(一级) - 批量提交审核
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAuditOne/auditBatch", method = RequestMethod.POST)
    public Wrapper<Void> auditOneBatchPlatformCoupon(@RequestBody @Valid CommonIdsRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.batchAuditOnePlatformCoupon(request, loginUser);
    }

    // =============================待审核平台优惠劵(二级)=============================

    /**
     * 待审核平台优惠劵(二级) - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAuditTwo/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponAuditPageResponse>> pageAuditTwoPlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageAuditTwoPlatformCoupon(request, loginUser);
    }

    /**
     * 待审核平台优惠劵(二级) - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/waitAuditTwo/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getAuditTwoPlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }


    /**
     * 待审核平台优惠劵(二级) - 审核
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAuditTwo/audit", method = RequestMethod.POST)
    public Wrapper<Void> auditTwoPlatformCoupon(@RequestBody @Valid CommonAgreeRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.auditTwoPlatformCoupon(request, loginUser);
    }

    /**
     * 待审核平台优惠劵(二级) - 批量审核
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitAuditTwo/auditBatch", method = RequestMethod.POST)
    public Wrapper<Void> auditTwoBatchPlatformCoupon(@RequestBody @Valid CommonIdsRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.batchAuditTwoPlatformCoupon(request, loginUser);
    }

    // =============================待提交平台优惠劵=============================

    /**
     * 待提交平台优惠劵 - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/waitSubmit/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSubmitPageResponse>> pageSubmitPlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageSubmitPlatformCoupon(request, loginUser);
    }

    /**
     * 待提交平台优惠劵 - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/waitSubmit/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getSubmitPlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }

    /**
     * 待提交平台优惠劵 - 批量提交
     * @param request 接口参数
     */
    @RequestMapping(value = "/waitSubmit/submitBatch", method = RequestMethod.POST)
    public Wrapper<Void> submitBatchPlatformCoupon(@RequestBody @Valid CommonIdsRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.submitPlatformCoupon(request, loginUser);
    }

    // =============================平台优惠劵执行=============================

    /**
     * 平台优惠劵执行 - 分页列表
     * @return 查询结果
     */
    @RequestMapping(value = "/waiteExecute/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponExecutePageResponse>> pageExecutePlatformCoupon(@Valid PlatformCouponPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageExecutePlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵执行 - 详情
     * @return 查询结果
     */
    @RequestMapping(value = "/waiteExecute/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponResponse> getExecutePlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getPlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵执行 - 发券
     * @param request 接口参数
     */
    @RequestMapping(value = "/waiteExecute/grant", method = RequestMethod.POST)
    public Wrapper<Void> grantPlatformCoupon(@RequestBody @Valid PlatformCouponGrantRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.grantPlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵执行 - 发券详情
     * @return 返回结果
     */
    @RequestMapping(value = "/waiteExecute/grant/get", method = RequestMethod.GET)
    public Wrapper<PlatformCouponGrantResponse> getGrantPlatformCoupon(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getGrantPlatformCoupon(request, loginUser);
    }

    /**
     * 平台优惠劵执行明细 - 查询条件
     * @return 返回结果
     */
    @RequestMapping(value = "/waiteExecute/detail/page/condition", method = RequestMethod.GET)
    public Wrapper<PlatformCouponDetailConditionResponse> getExecutePlatformCouponDetailCondition(@Valid CommonIdReq request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.getExecutePlatformCouponDetailCondition(request);
    }

    /**
     * 平台优惠劵执行明细 - 分页列表
     * @return 返回结果
     */
    @RequestMapping(value = "/waiteExecute/detail/page", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponDetailPageResponse>> pageExecutePlatformCouponDetail(@Valid PlatformCouponDetailPageRequest request) {
        UserLoginCacheDTO loginUser = getPlatformUser();
        return platformCouponService.pageExecutePlatformCouponDetail(request, loginUser);
    }
}
